package com.lagou.controller;

import com.lagou.domain.Employee;
import com.lagou.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;
    @RequestMapping("/saveEmployee")
    public String saveEmployee(Employee employee){

        employeeService.saveEmployee(employee);
        // 跳转到findAll方法从新查询一次数据库进行数据的遍历展示
        return "redirect:/employee/findAll";
    }
    @RequestMapping("/findAll")
    public String findAll(Model model){
        List<Employee> all = employeeService.findAll();
        model.addAttribute("all",all);
        return "allEm";
    }

}
